// utils/websocket.js
import SockJS from 'sockjs-client';
import Stomp from 'stompjs';

export function connectWebSocket(userType, id, callback) {
    const socket = new SockJS('http://localhost:8888/ws');
    const stompClient = Stomp.over(socket);
    
    stompClient.connect({}, () => {
        if (userType === 'teacher') {
            stompClient.subscribe(`/topic/checkin/teacher/${id}`, callback);
        } else if (userType === 'student') {
            stompClient.subscribe(`/topic/checkin/${id}`, callback);
        }
    });
    return stompClient;
}